<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let input = `abc1 A
        def A
        alic A
        xyz B`

        let spl = input.split('\n').map(v => v.trim())
        let obj = {
            A: [],
            B: [],
            C: [],
        }
        spl.forEach((v) => {
            let [x, y] = v.split(' ')
            obj[y].push(x)
        })

        if (obj['A'].length != 0 && obj['B'].length != 0 && obj['C'].length != 0) {
            console.log('no');
        } else {
            obj.A.sort()
            obj.B.sort()
            obj.C.sort()
            switch (0) {
                case obj.A.length:
                    console.log(...obj.B);
                    

                    break;
                case obj.B.length:
                    
                console.log(...obj.C);

                    break;
                case obj.C.length:
                    
                console.log(...obj.A);

                    break;

                default:
                    break;
            }
        }


    </script>
</body>

</html>